package utils.global.constant;

import org.springframework.util.ObjectUtils;

import java.util.HashMap;


public abstract class BaseException extends Exception {

    protected RestfulJson<HashMap> restfulJson = RestfulJson.error();

    public BaseException() {
        init();
    }

    /**
     * set default show error message
     */
    public abstract void init();

    public BaseException(String message, HashMap<String, Object> data) {
        super(message);
        init();
        restfulJson.setMsg(message);
        if (!ObjectUtils.isEmpty(data)) {
            restfulJson.setData(data);
        }
    }

    public BaseException(String message, Throwable cause, HashMap<String, Object> data) {
        super(message, cause);
        init();
        restfulJson.setMsg(message);
        if (!ObjectUtils.isEmpty(data)) {
            restfulJson.setData(data);
        }
    }

    public BaseException(Throwable cause, HashMap<String, Object> data) {
        super(cause);
        init();
        if (!ObjectUtils.isEmpty(data)) {
            restfulJson.setData(data);
        }
    }

    public RestfulJson getRestfulJson() {
        return restfulJson;
    }
}
